from Utils.command.CommandHistory import CommandHistory
from Utils.command.createOutlineCommand import CreateOutlinesCommand
from Utils.command.createPointCommand import CreatePointCommand
from Utils.command.createSurfaceCommand import CreateSurfaceCommand
from Utils.command.ActorType import ActorType    

class ActorManager:
    """
    Actor 管理类，包含添加和移除 actor 的方法。
    """
    
    def __init__(self, app):
        self.app = app
        self.history = CommandHistory()

    def add(self,type:ActorType, poly_data,options=dict()):
        if type==ActorType.OUTLINES:
            actor = CreateOutlinesCommand(poly_data,options).actor
        elif type==ActorType.POINTS:
            actor = CreatePointCommand(poly_data,options).actor
        # elif type=='LABEL':
        #     actor = 
        # elif type=='GRAPHIC_ACTOR':
        
        else :
            actor = CreateSurfaceCommand(poly_data,options).actor
        self.history.add(actor)
        self.app.add(actor)

    def undo(self):
        actor = self.history.undo()
        if actor is not None:
            self.app.remove(actor)
            self.app.export_image()
        
    def redo(self):
        actor = self.history.redo()
        if actor is not None:
            self.app.add(actor)
            self.app.export_image()
            